home *** CD-ROM | disk | FTP | other *** search
- Path: trib.apple.com!usenet
- From: Amir <Amir@bayarea.net>
- Newsgroups: comp.lang.c++
- Subject: Re: Experiences calling C++ from C?
- Date: Mon, 08 Apr 1996 10:36:55 -0700
- Organization: Apple Computer, Inc., Cupertino, California
- Message-ID: <31694EB7.6C0C@bayarea.net>
- References: <SCHOLZ.96Apr7012849@otto.inf.fu-berlin.de>
- NNTP-Posting-Host: a17-128-200-53.apple.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (Macintosh; I; PPC)
-
- >
- > Hello,
- >
- > I would greatly appreciate any help with calling C++ functions
- > from C!
- >
- > I have read the FAQ, I know that one must declare the C++
- > functions with "extern C++" and I'm passing nothing but void pointers
- > (no structs), but still my program crashes in the first C++ function:
- > The gdb stack shows a number of invocations of some unknown-to-me
- > function _end (), followed by a segmentation fault in a constructor
- > function I never call.
- >
- > Any help will be most welcome!
- >
- > Enno
-
- Hello
-
- I'll try to guess what is the problem. I dealt with that
- a couple of years ago, so if I don't remember correctly, I hope
- someone will give the right answer.
-
- if you have a Global variables in the C++ module, Its
- constructors and destructors are called from a special
- functions that are created by the C++ compiler for each
- module that has Global variables.
-
- Now, if I remember correctly, if your main is in C, these function
- that should be called before the main are never called.
- so you have three solutions:
-
- 1. Make the main in the C++ part (prob you need to link with a C++
- linker)
- 2. Don't have any global instances.
- 3. If you must have the main in C, and you must have global
- variables, you can find the name of all the special functions
- and call them yourself as the VERY FIRST lines in your C main
- function (this is what I had to do)
-
-
- Amir
-
- --
-
- \\||||//
- \ o o /
- ______________.ooO__( () )__Ooo._______________________________
-
- Amir Deutel http://www.bayarea.net/~amir/
-
- .oo0O O0oo. Work: Amir.D@AppleLink.Apple.com
- ( ) ( ) Home: Amir@bayarea.net
- __________________\ (_____) /____________________________________
- \_) (_/
-